<?
require_once("../config/dbconn.php");require_once("../config/powercls.php");require_once("../config/pagecls.php");
if($action=='isok'){
	$sql="select * from {$db_prefix}cx where id='$id'";
	$rs=$db->get_one($sql);
	if ($rs['state']!=1){
		$msg="提现状态错误\\n";
	}
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	//连接数据库，取出该用户的可用余额
	$sqlsky="select * from {$db_prefix}users where username='".$rs['username']."'";
	$rsky=$db->get_one($sqlsky);
	$cxmoney=$rsky["cxmoney"];
	if($rs['wp']>$cxmoney)
	{
		echo "<script>alert('金额不足');history.back();</script>";exit();
	}
	// 可用余额-重消金额
	$sqlkkk="update {$db_prefix}users set cxmoney=cxmoney-'".floatval($rs['wp'])."' where username='".$rs['username']."'";
	$db->query($sqlkkk);
	unset($dataArray);
	$dataArray['state']=2;
	$dataArray['edittime']=$curtime;
	$db->update("{$db_prefix}cx",$dataArray,"id='$id'");
	echo "<script>location.href='cx_goods.php?pageno={$pageno}';</script>";exit();
}
if($action=='del'){
	$db->delete("{$db_prefix}cx","id='$id'");
	echo "<script>location.href='cx_goods.php?pageno={$pageno}';</script>";exit();
}

if($action=='isno'){
	$sql="select * from {$db_prefix}cx where id='$id'";
	$rs=$db->get_one($sql);
	unset($dataArray);
	$dataArray['state']=3;
	$dataArray['edittime']=$curtime;
	$db->update("{$db_prefix}cx",$dataArray,"id='$id'");
	echo "<script>location.href='cx_goods.php?pageno={$pageno}';</script>";exit();
}
 $query='';$querystr='?action=query';
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="../calendar/WdatePicker.js"></script>
</script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
font-size:12px;
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.red {	color:#FF0000
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">商品兑换管理</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
               
              </table></td>
            </tr>
            <tr>
              <td height="30"><form name="myform" method="post" action="?action=agreeall">
                <table width="100%" height="60" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td height="30" align="center" bgcolor="#f2f2f2" >编号</td>
                    <td align="center" bgcolor="#f2f2f2" >用户名</td>
				    <td align="center" bgcolor="#f2f2f2" >兑换商品</td>
                    <td align="center" bgcolor="#f2f2f2" >状态</td>
                    <td align="center" bgcolor="#f2f2f2" >申请时间</td>
					<td align="center" bgcolor="#f2f2f2" >审核时间</td>
                    <td height="30" align="center" bgcolor="#f2f2f2" >操作</td>
                  </tr>
                  <?
 
  $sql="select count(id) as c  from {$db_prefix}cx where 1";
  if ($query!='') $sql.=$query;
  $rs=$db->get_one($sql);
  $page=new pagecls(20,intval($rs['c']));
  $sql="select * from {$db_prefix}cx where 1";
  if ($query!='') $sql.=$query;
  $sql.=" order by id desc limit {$page->pastnum},{$page->pagesize}";
  $result=$db->query($sql);
  while($rs=$db->fetch_array($result)){
  ?>
                  <tr>
                    <td align="center"><?=$rs['id']?></td>
                    <td align="center"><?=$rs['username']?></td>
					<td align="center"><?=$rs['wp']?></td>
                    <td align="center" class="left_txt3" ><? if ($rs['state']==1) echo "等待审核";elseif ($rs['state']==2) echo "兑换成功";elseif($rs['state']==3) echo "兑换失败";?></td>
                    <td align="center" ><?=date("Y-m-d H:i:s",$rs['addtime'])?></td>
                    <td align="center" ><? if ($rs['edittime']>0) echo date("Y-m-d H:i:s",$rs['edittime'])?></td>
                    <td height="10" align="center" >
                      <?
				  if ($rs['state']==1){
				  ?>
                        <a href="?action=isok&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick='return confirm("确定审核吗？")'>审核</a>|<a href="?action=isno&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick="return confirm('确定拒绝吗？')">拒绝</a>|<a href="?action=del&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick='return confirm("确定删除吗？")'>删除</a>
                      <?
				  }
				  ?>
				   <?
				  if ($rs['state']==2){
				  ?>
                     已审核
                      <?
				  }
				  ?>
				   <?
				  if ($rs['state']==3){
				  ?>
                       已拒绝
                      <?
				  }
				  ?>
                  <a href="?action=del&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>" onClick='return confirm("确定删除吗？")'>删除</a>
                      </td>
                  </tr>
                  <?
  }
  $db->free_result($result);
  ?>
                </table>
                            </form>
              <label></label></td>
            </tr>
            
            <tr></tr>
            <tr>
              <td height="30" align="right">每页<?=$page->pagesize?>条 第<?=$page->pageno?>/<?=$page->pagenum?>页 共<?=$page->recnum?>条 <a href='?<?=$page->url?>1'><img src="image1/first.gif" border="0"></a>   <a href='?<?=$page->url.($page->pageno-1)?>'><img src="image1/back.gif" border="0"></a>  <a href='?<?=$page->url.($page->pageno+1)?>'><img src="image1/next.gif" border="0"></a>   <a href='?<?=$page->url.$page->pagenum?>'><img src="image1/last.gif" border="0"></a></td>
              </tr>
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
